/* The file is saved in UTF-8 codepage.
 * Check: «Stereotype», Section mark-§, Copyright-©, Alpha-α, Beta-β, Smile-☺
 */
package cz.pecinovsky.english.lootp.utility;



////////////////////////////////////////////////////////////////////////////////
//%%+  +++++ End of ignored starting test - place for imports +++++

//%X+ xxxxx Start of the ovejumped text with declaration of the envelope xxxxx
/*******************************************************************************
 *<pre>
 * Předchozí:   No - this is a newly defined type
 *              Ttt in the project Ppp
 * Následující: No
 *
 * Project  Ppp
 *   + Adeed
 *   - Removed
 *   ~ Changed
 *</pre>
 *
 * @author Rudolf PECINOVSKÝ
 * @version 6.03.2017 — 2010-11-08
 */
////////////////////////////////////////////////////////////////////////////////
//%X- ----- End of the ovejumped text with declaration of the envelope -----


/*******************************************************************************
 * Instances of class {@code Position} are trasport objects (crates)
 * containing dimensions.
 * Their attributes are therefore defined as public constants.
 *
 * @author Rudolf PECINOVSKÝ
 * @version 6.03.2017 — 2010-11-08
 */
public class Size
{
//== CONSTANT CLASS ATTRIBUTES =================================================
//%X+ <999

    private static final int INIT_HASH_CODE = Integer.MIN_VALUE;



//== VARIABLE CLASS ATTRIBUTES =================================================
//== STATIC CONSTRUCTOR (CLASS INITIALIZER, STATIC INICITALIZING BLOCK) ========
//== CONSTANT INSTANCE ATTRIBUTES ==============================================

    /** Object width. */
    public final int width;

    /** Object height. */
    public final int height;



//== VARIABLE INSTANCE ATTRIBUTES===============================================
//== CLASS GETTERS AND SETTERS =================================================
//== OTHER NON-PRIVATE CLASS METHODS ===========================================

//##############################################################################
//== CONSTUCTORS AND FACTORY METHODS============================================

    /***************************************************************************
     * Creates a crate containing given dimensions.
     *
     * @param width  Object width
     * @param height Object height
     */
    public Size(int width, int height)
    {
        this.width = width;
        this.height = height;
    }



//== ABSTRACT METHODS ==========================================================
//== INSTANCE GETTERS AND SETTERS ==============================================

    /***************************************************************************
     * Returns the object width.
     *
     * @return  Object width
     */
    public int getWidth()
    {
        return width;
    }


    /***************************************************************************
     * Returns the object height.
     *
     * @return  Object height
     */
    public int getHeight()
    {
        return height;
    }



//== OTHER NON-PRIVATE INSTANCE METHODS ========================================
//%A+ >127

    /***************************************************************************
     * Indicates whether the object referred by the parameter
     * represets the same size.
     *
     * @param object The object with which to compare
     * @return {@code true} if this object points to the same size
     *         as the argument object; {@code false} otherwise.
     */
    @Override
    public boolean equals(Object object)
    {
//%A-
//%I+ >127 -135
//        return (object instanceof Size)      &&
//               (((Size)object).x == this.x)  &&
//               (((Size)object).y == this.y);
//%I-
//%A+ >135
        if (! (object instanceof Size)) {
            return false;               //==========>
        }
        Size other = (Size)object;
        return (other.width == this.width)  &&  (other.height == this.height);
//%A-
//%A+ >127
    }

//%A-
//%X+ <999

    /***************************************************************************
     * Returns the hash code of the instance.
     *
     * @return  Hash code of the instance
     */
    @Override
    public int hashCode()
    {
        return 1234567 + 37*(37*width + height);
    }

//%X-
//%X+ <126

    /***************************************************************************
     * Returns a string representation of the instance.
     * It is used mostly for debugging purposes.
     *
     * @return String representation of the instance
     */
    @Override
    public String toString()
    {
        return "Size[width=" + width + ", height=" + height + "]";
    }

//%X-
//%X+ <999

    /***************************************************************************
     * Returns a new size computed from this one
     * by adding the given dimensions.
     *
     * @param  dWidth   Width chang (>0=increase, <0=decrease).
     * @param  dHeight  Height change (>0=increase, <0=decrease).
     * @return The new size
     */
    public Size resizeBy(int dWidth, int dHeight)
    {
        return new Size(width + dWidth,  height + dHeight);
    }


    /***************************************************************************
     * Returns a new size comuted from this one
     * by adding the given dimensions.
     *
     * @param  change The crate with values of requested changes
     * @return The new size
     */
    public Size resizeBy(Size change)
    {
        return new Size(width + change.width,  height + change.height);
    }



//%X-
//== PRIVATE AND AUXILIARY CLASS METHODS =======================================
//== PRIVATE AND AUXILIARY INSTANCE METHODS ====================================
//== EMBEDDED AND INNER CLASSES ================================================
//== TESTING CLASSES AND METHODS ===============================================
//
//    /***************************************************************************
//     * Test method.
//     */
//    public static void test()
//    {
//        Size inst = new Size();
//    }
//    /** @param args Command line arguments - they are not used. */
//    public static void main(String[] args)  {  test();  }
}
